﻿	<div class="easyui-layout" style="height:525px;width:948px;overflow:hidden;margin:0px auto">
		<div data-options="region:'west',split:false" style="width:250px;background:#dbeaf9;overflow:hidden;">
			<div class="easyui-panel" data-options="title:'查询条件',border:false">
				<form  id="fbs_west_form" action="post">
					<table id="fbs_west_form_table"  cellspacing="15" cellpadding="0">
						<tr><td>日期从</td><td><input id="startdate" type="text" class="easyui-datebox"/></td></tr>
						<tr><td>日期至</td><td><input id="enddate" type="text" class="easyui-datebox"/></td></tr>
						<tr><td>员工</td><td><select id="fbs_west_employee_combotree" class="easyui-combotree"style="width:130px;" data-options = "'panelHeight':150"></select></td></tr>
						<tr><td>机构</td><td><select id="fbs_west_org_combotree" class="easyui-combotree"style="width:130px;" data-options = "'panelHeight':150"></select></td></tr>
						<tr><td>科室</td><td><select id="fbs_west_dept_combotree" class="easyui-combotree"style="width:130px;" data-options = "'panelHeight':150"></select></td></tr>
						<tr><td>医生</td><td><select id="fbs_west_doctor_combotree" class="easyui-combotree"style="width:130px;" data-options = "'panelHeight':150"></select></td></tr>
						<tr><td>&nbsp;</td><td align="right"><a id="btn" href="javascript:void(0)"  onclick="formSearch();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:false">查询</a></td></tr>
					</table>
				</form>

			</div>
		</div>
		<div data-options="region:'center'">
		   <div class="easyui-panel" data-options="title:'&nbsp;',fit:true,border:false,iconCls:'icon-save',tools: [{   
			    iconCls:'icon-refresh',   
			    handler:function(){
			        fbs_refresh();
			    }   
			  }]">
		        
				  
					    <table id="fbs_center_datagrid"></table>
					
				    <!--	<div data-options="region:'south',split:false,border:false" style="height:30px;">
					     <div id="pp" class="easyui-pagination" style="background:#efefef;"></div> 
					</div> -->
				
				
		   </div>
			 
		</div>
	</div>
<script type="text/javascript">
var fbs_center_datagrid;
var fbs_ovaldate = new Date();
var fbs_ovaldateStr = formatCalendarDate(fbs_ovaldate,'-');
$(function(){
     getVisiptplanShowData();
	 getEmployeeData();

});

function getVisiptplanShowData() {
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedbackshow', 'visitfeedback',"{'currentdate':'" + fbs_ovaldateStr +"'}");
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getVisiptplanDayDataReturn);
	};

function getVisiptplanDayDataReturn(data) {
	var str,tempResult,rowData;
    if(data.successflag == 'false') {
		return;
	}
	tempResult = data.result;
	if (typeof(tempResult) == 'undefined') {
		return;
	}
	if (typeof(tempResult.dates) != 'undefined') {
	   if(!searchFlag){
	   var startendDate = tempResult.dates.weekrange.split('~');
	   $('#startdate').datebox('setValue', startendDate[0]);
	   $('#enddate').datebox('setValue', startendDate[1]);
	   }
	}
    
	if (typeof(tempResult.rows) != 'undefined') {
		str = '{"total":' + tempResult.count + ',"rows":' + JSON.stringify(tempResult.rows) + '}';
	} else {
		str = '{"total":0,"rows":[]}';
	}
	rowData =  $.parseJSON(str);
	fbs_center_datagrid = $('#fbs_center_datagrid').datagrid({
			border : false,
			striped : true,
			nowrap:true,
			fitColumns : true,
			height:300,
			idField:'visitfeedbackid',
			fit : true,
			singleSelect : true,
			pagination : true,
			columns : [[{
						field : 'feedbackdate',
						title : '日期',
						width : 80,
						resizable : false,
						sortable:true
					}, {
						field : 'daytype',
						title : '拜访时间',
						width : 80,
						resizable : false,
						sortable:true,
						formatter: function(value,row,index){
				             if (value != 'pm'){
					             return '上午';
				             } else {
					             return '下午';
				            }
			            }
					}, {
						field : 'orgname',
						title : '机构',
						width : 250,
						resizable : false
					}, {
						field : 'deptname',
						title : '科室',
						width : 150,
						resizable : false
					}, {
						field : 'doctorname',
						title : '医生',
						width : 80,
						resizable : false
					}
				]]
		});
	fbs_center_datagrid.datagrid('loadData',rowData);
	var p = fbs_center_datagrid.datagrid('getPager');
	$(p).pagination({
	    pageSize:17,
		pageList:[17,34],
		onSelectPage : function (pageNumber, pageSize) {
			getVisiptplanDayDataPage(pageNumber, pageSize);
		}
	});
}


function getVisiptplanDayDataPage(pageNumber,pageSize) {
		if(typeof(pageNumber) == 'undefined' && typeof(pageSize) == 'undefined'){
		    var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		    var value = new Array('wsActionJSON', token, 'p_visitfeedbackshow', 'visitfeedback','');
		}else{
		    var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		    var value = new Array('wsActionJSON', token, 'p_visitfeedbackshow', 'visitfeedback',"{'jumppage':"+pageNumber+",'maxitem':"+pageSize+",'theendindex':"+ (pageNumber-1)*pageSize + "}");
		}
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getVisiptplanDayDataPageReturn);
	};

function getVisiptplanDayDataPageReturn(data){
    var str,tempResult,rowData;
    if (data.successflag == 'false') {
		return;
	}
	tempResult = data.result;
	if (typeof(tempResult) == 'undefined') {
		return;
	}
    if(typeof(tempResult.rows) != 'undefined'){
      str='{"total":'+tempResult.count +',"rows":'+ JSON.stringify(tempResult.rows)+'}';
    }else{
      str='{"total":0,"rows":[]}';
    }
    rowData =  $.parseJSON(str);
 	fbs_center_datagrid.datagrid('loadData', rowData);
}



function fbs_refresh(){
     getVisiptplanShowData();
}

var searchFlag = false;
function formSearch() {
    searchFlag = true;
    var startdate,enddate,employeeid
	startdate = $('#startdate').datebox('getValue');
	enddate = $('#enddate').datebox('getValue');
	employeeid = fbs_west_employee_combotree.combotree('getValue');
    var params = "{'startdate':'"+startdate+"','enddate':'"+enddate+"','employeeid':'"+employeeid+"'}";
	var variable = new Array('__methodName', '__token', 'pagename', 'actionname', '__params');
	var value = new Array('wsActionJSON', token, 'p_visitfeedbackshow', 'visitfeedback', params);
	var dataStr = getJsonData(variable, value);
	connectionServlet(dataStr, getVisiptplanDayDataReturn);
}


function getEmployeeData(){
	var variable = new Array('__methodName', '__token', 'pagename', 'actionname', '__params');
	var value = new Array('wsActionJSON', token, 'p_usersynctree', 'usersync', "");
	var dataStr = getJsonData(variable, value);
	connectionServlet(dataStr, getEmployeeDataReturn);
}

var fbs_west_employee_combotree,tree,tree_node;var id = 0;
function getEmployeeDataReturn(data){
var tempResult,rowsData;
   if (data.successflag == 'false') {
		return;
	}
	tempResult = data.result;
	if (typeof(tempResult) == 'undefined') {
		return;
	}
	if (typeof(tempResult.userfirstlist) != 'undefined') {
		rowsData = tempResult.userfirstlist;
	}else{
	    rowsData = [];
	}
   fbs_west_employee_combotree = $('#fbs_west_employee_combotree');
   fbs_west_employee_combotree.combotree('loadData',rowsData);
   tree = fbs_west_employee_combotree.combotree('tree');
   if(tree){
        tree.tree({
		    onBeforeExpand:function(node){
				tree_node = node;
				     if(strt.indexOf(node.id) == -1){
				       getNextEmployeeData(node.id);
					 }
			}
		});
   }
  
}


function getNextEmployeeData(id){
	var variable = new Array('__methodName', '__token', 'pagename', 'actionname', '__params');
	var value = new Array('wsActionJSON', token, 'p_usersynctree', 'usersync', "{'parentuserid':"+id+"}");
	var dataStr = getJsonData(variable, value);
	console.info(dataStr);
	connectionServlet(dataStr, getNextEmployeeDataReturn);
}
var strt='';
function getNextEmployeeDataReturn(data){
var tempResult,rowsData;
   if (data.successflag == 'false') {
		return;
	}
	tempResult = data.result;
	if (typeof(tempResult) == 'undefined') {
		return;
	}
	if (typeof(tempResult.userfirstlist) != 'undefined') {
		rowsData = tempResult.userfirstlist;
	}else{
	    rowsData = [];
	}
    tree.tree('append',{
		   parent: tree_node.target,
		   data:rowsData
    });
	 strt += tree_node.id+',';
	 tree.tree('collapse',tree_node.target);
     tree.tree('expand',tree_node.target);


}
</script>
